package com.bootdo.common.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/9/15.
 */
public class ParticipleUtil {

    public Map<String, String> segMore(String text) {
        Map<String, String> map = new HashMap<>();
        map.put("智能切分", segText(text, true));
        map.put("细粒度切分", segText(text, false));
        return map;
    }

    /**
     *
     * @param text 文本
     * @param useSmart true:只能切分 false：细粒度切分
     * @return
     */
    public static String segText(String text, boolean useSmart) {
        StringBuilder result = new StringBuilder();
        IKSegmenter ik = new IKSegmenter(new StringReader(text), useSmart);
        try {
            Lexeme word = null;
            while((word=ik.next())!=null) {
                result.append(word.getLexemeText()).append("");
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return result.toString();
    }


    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("智能切分", segText("我爱楚离陌", true));
        map.put("细粒度切分", segText("我爱你楚离陌", false));
        System.out.print(map.toString());

    }


}
